package com.shop2cn.iapi.agentproducts.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.ClearVirtualStockBean;
import com.shop2cn.iapi.agentproducts.parameter.ProductDetailsBean;
import com.shop2cn.iapi.agentproducts.parameter.ProductDetailsDto;
import com.shop2cn.iapi.agentproducts.service.ClearVirtualStockCall;
import com.shop2cn.iapi.agentproducts.service.ProductDetailsCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.utils.AgentUsers;
/**
*清空虚拟库存Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_ClearVirtualStock{
	private static ClearVirtualStockBean clearvirtualstockBean;
	private static ClearVirtualStockCall clearvirtualstockCall;
	// 渠道商
	private static int rootUserId = AgentUsers.rootUserId;
	private static String rootUserName = "NickautoTest";
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("清空虚拟库存Test");
	}
	
	@Before
	public void caseUp() {
		clearvirtualstockBean=new ClearVirtualStockBean();
		clearvirtualstockCall=new ClearVirtualStockCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(clearvirtualstockCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ClearVirtualStock_001() {
		Logger.start(true,"清除虚拟库存，成功");
		try {
			ProductDetailsBean productdetailsBean = new ProductDetailsBean();
			ProductDetailsCall productdetailsCall = new ProductDetailsCall();
			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			rootUserId=mchid;
			
			
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, true);
			addAgentProductBean.getCatalogList().get(0).setVirtualStock(30);
			addAgentProductBean.getCatalogList().get(0).setStock(40);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			productdetailsBean = AddAgentProductCallService.initGetProductDetails(rootUserId, rootUserId, productId,
					true);
			
			productdetailsCall.setData(productdetailsBean);
			productdetailsCall.callService();
			
			Logger.verifyEquals("200", productdetailsCall.getString("code"), "验证code");
			ProductDetailsDto productDetails = productdetailsCall.getProductDetails();
			// 判断虚拟库存真实库存
			Logger.verifyEquals(70,productDetails.getCatalogList().get(0).getStock(), "总库存查询");
			Logger.verifyEquals(40,productDetails.getCatalogList().get(0).getRealStock(), "真实库存查询");
			Logger.verifyEquals(30,productDetails.getCatalogList().get(0).getVirtualStock(), "虚拟库存查询");
			
			clearvirtualstockBean.setUserId(rootUserId);
			clearvirtualstockBean.setFuncType(1);
			clearvirtualstockCall.setData(clearvirtualstockBean);
			clearvirtualstockCall.callService();			
			Logger.verifyEquals("ok", clearvirtualstockCall.getReturnData(), "验证code");
			
			productdetailsCall.callService();
			
			Logger.verifyEquals("200", productdetailsCall.getString("code"), "验证code");
			productDetails = productdetailsCall.getProductDetails();
			// 判断虚拟库存真实库存
			Logger.verifyEquals(40,productDetails.getCatalogList().get(0).getStock(), "总库存查询");
			Logger.verifyEquals(40,productDetails.getCatalogList().get(0).getRealStock(), "真实库存查询");
			Logger.verifyEquals(0,productDetails.getCatalogList().get(0).getVirtualStock(), "虚拟库存查询");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ClearVirtualStock_002() {
		Logger.start(true,"mchhId不对，返回ok。。。");
		try {
			clearvirtualstockBean.setUserId(1233311);
			clearvirtualstockCall.setData(clearvirtualstockBean);
			clearvirtualstockCall.callService();			
			Logger.verifyEquals("ok", clearvirtualstockCall.getReturnData(), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ClearVirtualStock_003() {
		Logger.start(true,"本来就无虚拟库存，成功");
		try {
			ProductDetailsBean productdetailsBean = new ProductDetailsBean();
			ProductDetailsCall productdetailsCall = new ProductDetailsCall();
			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			rootUserId=mchid;
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, true);
			addAgentProductBean.getCatalogList().get(0).setStock(40);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			productdetailsBean = AddAgentProductCallService.initGetProductDetails(rootUserId, rootUserId, productId,
					true);
			productdetailsCall.setData(productdetailsBean);
			productdetailsCall.callService();
			
			Logger.verifyEquals("200", productdetailsCall.getString("code"), "验证code");
			ProductDetailsDto productDetails = productdetailsCall.getProductDetails();
			// 判断虚拟库存真实库存
			Logger.verifyEquals(40,productDetails.getCatalogList().get(0).getStock(), "总库存查询");
			Logger.verifyEquals(40,productDetails.getCatalogList().get(0).getRealStock(), "真实库存查询");
			Logger.verifyEquals(0,productDetails.getCatalogList().get(0).getVirtualStock(), "虚拟库存查询");
			
			clearvirtualstockBean.setUserId(rootUserId);
			clearvirtualstockBean.setFuncType(1);
			clearvirtualstockCall.setData(clearvirtualstockBean);
			clearvirtualstockCall.callService();			
			Logger.verifyEquals("ok", clearvirtualstockCall.getReturnData(), "验证code");
			
			productdetailsCall.callService();
			
			Logger.verifyEquals("200", productdetailsCall.getString("code"), "验证code");
			productDetails = productdetailsCall.getProductDetails();
			// 判断虚拟库存真实库存
			Logger.verifyEquals(40,productDetails.getCatalogList().get(0).getStock(), "总库存查询");
			Logger.verifyEquals(40,productDetails.getCatalogList().get(0).getRealStock(), "真实库存查询");
			Logger.verifyEquals(0,productDetails.getCatalogList().get(0).getVirtualStock(), "虚拟库存查询");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ClearVirtualStock_004() {
		Logger.start(true,"重复请求，没关系，成功");
		try {
			ProductDetailsBean productdetailsBean = new ProductDetailsBean();
			ProductDetailsCall productdetailsCall = new ProductDetailsCall();
			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			rootUserId=mchid;
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, true);
			addAgentProductBean.getCatalogList().get(0).setVirtualStock(30);
			addAgentProductBean.getCatalogList().get(0).setStock(40);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			productdetailsBean = AddAgentProductCallService.initGetProductDetails(rootUserId, rootUserId, productId,
					true);
			productdetailsCall.setData(productdetailsBean);
			productdetailsCall.callService();
			
			Logger.verifyEquals("200", productdetailsCall.getString("code"), "验证code");
			ProductDetailsDto productDetails = productdetailsCall.getProductDetails();
			// 判断虚拟库存真实库存
			Logger.verifyEquals(70,productDetails.getCatalogList().get(0).getStock(), "总库存查询");
			Logger.verifyEquals(40,productDetails.getCatalogList().get(0).getRealStock(), "真实库存查询");
			Logger.verifyEquals(30,productDetails.getCatalogList().get(0).getVirtualStock(), "虚拟库存查询");
			
			clearvirtualstockBean.setUserId(rootUserId);
			clearvirtualstockBean.setFuncType(1);
			clearvirtualstockCall.setData(clearvirtualstockBean);
			clearvirtualstockCall.callService();			
			clearvirtualstockCall.callService();			
			Logger.verifyEquals("ok", clearvirtualstockCall.getReturnData(), "验证code");
			
			productdetailsCall.callService();
			
			Logger.verifyEquals("200", productdetailsCall.getString("code"), "验证code");
			productDetails = productdetailsCall.getProductDetails();
			// 判断虚拟库存真实库存
			Logger.verifyEquals(40,productDetails.getCatalogList().get(0).getStock(), "总库存查询");
			Logger.verifyEquals(40,productDetails.getCatalogList().get(0).getRealStock(), "真实库存查询");
			Logger.verifyEquals(0,productDetails.getCatalogList().get(0).getVirtualStock(), "虚拟库存查询");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ClearVirtualStock_005() {
		Logger.start(true,"funcType为0  不清除虚拟库存");
		try {
			ProductDetailsBean productdetailsBean = new ProductDetailsBean();
			ProductDetailsCall productdetailsCall = new ProductDetailsCall();
			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			rootUserId=mchid;
			
			
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, true);
			addAgentProductBean.getCatalogList().get(0).setVirtualStock(30);
			addAgentProductBean.getCatalogList().get(0).setStock(40);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			productdetailsBean = AddAgentProductCallService.initGetProductDetails(rootUserId, rootUserId, productId,
					true);
			
			productdetailsCall.setData(productdetailsBean);
			productdetailsCall.callService();
			
			Logger.verifyEquals("200", productdetailsCall.getString("code"), "验证code");
			ProductDetailsDto productDetails = productdetailsCall.getProductDetails();
			// 判断虚拟库存真实库存
			Logger.verifyEquals(70,productDetails.getCatalogList().get(0).getStock(), "总库存查询");
			Logger.verifyEquals(40,productDetails.getCatalogList().get(0).getRealStock(), "真实库存查询");
			Logger.verifyEquals(30,productDetails.getCatalogList().get(0).getVirtualStock(), "虚拟库存查询");
			
			clearvirtualstockBean.setUserId(rootUserId);
			clearvirtualstockBean.setFuncType(0);
			clearvirtualstockCall.setData(clearvirtualstockBean);
			clearvirtualstockCall.callService();			
			Logger.verifyEquals("ok", clearvirtualstockCall.getReturnData(), "验证code");
			
			productdetailsCall.callService();
			
			Logger.verifyEquals("200", productdetailsCall.getString("code"), "验证code");
			productDetails = productdetailsCall.getProductDetails();
			// 判断虚拟库存真实库存
			Logger.verifyEquals(70,productDetails.getCatalogList().get(0).getStock(), "总库存查询");
			Logger.verifyEquals(40,productDetails.getCatalogList().get(0).getRealStock(), "真实库存查询");
			Logger.verifyEquals(30,productDetails.getCatalogList().get(0).getVirtualStock(), "虚拟库存查询");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ClearVirtualStock_006() {
		Logger.start(true,"funcType为2  不清除虚拟库存");
		try {
			ProductDetailsBean productdetailsBean = new ProductDetailsBean();
			ProductDetailsCall productdetailsCall = new ProductDetailsCall();
			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			rootUserId=mchid;
			
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, true);
			addAgentProductBean.getCatalogList().get(0).setVirtualStock(30);
			addAgentProductBean.getCatalogList().get(0).setStock(40);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			productdetailsBean = AddAgentProductCallService.initGetProductDetails(rootUserId, rootUserId, productId,
					true);
			
			productdetailsCall.setData(productdetailsBean);
			productdetailsCall.callService();
			
			Logger.verifyEquals("200", productdetailsCall.getString("code"), "验证code");
			ProductDetailsDto productDetails = productdetailsCall.getProductDetails();
			// 判断虚拟库存真实库存
			Logger.verifyEquals(70,productDetails.getCatalogList().get(0).getStock(), "总库存查询");
			Logger.verifyEquals(40,productDetails.getCatalogList().get(0).getRealStock(), "真实库存查询");
			Logger.verifyEquals(30,productDetails.getCatalogList().get(0).getVirtualStock(), "虚拟库存查询");
			
			clearvirtualstockBean.setUserId(rootUserId);
			clearvirtualstockBean.setFuncType(2);
			clearvirtualstockCall.setData(clearvirtualstockBean);
			clearvirtualstockCall.callService();			
			Logger.verifyEquals("ok", clearvirtualstockCall.getReturnData(), "验证code");
			
			productdetailsCall.callService();
			
			Logger.verifyEquals("200", productdetailsCall.getString("code"), "验证code");
			productDetails = productdetailsCall.getProductDetails();
			// 判断虚拟库存真实库存
			Logger.verifyEquals(70,productDetails.getCatalogList().get(0).getStock(), "总库存查询");
			Logger.verifyEquals(40,productDetails.getCatalogList().get(0).getRealStock(), "真实库存查询");
			Logger.verifyEquals(30,productDetails.getCatalogList().get(0).getVirtualStock(), "虚拟库存查询");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
}
